//
//  ViewController.m
//  RACExample
//
//  Created by 山刘 on 2019/8/29.
//  Copyright © 2019 山刘. All rights reserved.
//

#import "ViewController.h"

@interface TabViewVO : NSObject
@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSString *target;
-(instancetype)initWithTitle:(NSString*)title Target:(NSString*)target;
@end
@implementation TabViewVO
-(instancetype)initWithTitle:(NSString*)title Target:(NSString*)target{
    if (self == [ super init]) {
        _title = title;
        _target = target;
    }
    return self;
}
@end

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSArray<TabViewVO*> *dataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //NSObject -> self.rac_deallocDisposable
    //NSObject -> self.rac_willDeallocSignal
    //UITableViewCell -> rac_prepareForReuseSignal
    
    _dataSource = @[
        [[TabViewVO alloc]initWithTitle:@"Test" Target:@"TestViewController"],
        [[TabViewVO alloc]initWithTitle:@"热信号、冷信号" Target:@"HotColdSignalViewController"],
        [[TabViewVO alloc]initWithTitle:@"RACSignal Demo" Target:@"RACSignalViewController"],
        [[TabViewVO alloc]initWithTitle:@"RACommand Demo" Target:@"RACommandViewController"],
        [[TabViewVO alloc]initWithTitle:@"MVVM与ReactiveCocoa的运用-1" Target:@"RACAndMVVMViewController01"],
        [[TabViewVO alloc]initWithTitle:@"MVVM与ReactiveCocoa的运用-2" Target:@"RACAndMVVMViewController02"],
        [[TabViewVO alloc]initWithTitle:@"MVVM与ReactiveCocoa的运用-3" Target:@"RACAndMVVMViewController03"],
        [[TabViewVO alloc]initWithTitle:@"豆瓣示例" Target:@"DouBanViewController"],
        [[TabViewVO alloc]initWithTitle:@"豆瓣电影列表" Target:@"DouBanViewDetailController"],
        [[TabViewVO alloc]initWithTitle:@"登录" Target:@"LoginViewController"],
        [[TabViewVO alloc]initWithTitle:@"圈子" Target:@"CircleListViewController"],
        [[TabViewVO alloc]initWithTitle:@"UITextField双向绑定" Target:@"TextFieldAndTableCellViewController"],
        [[TabViewVO alloc]initWithTitle:@"倒计时" Target:@"RASecondsCountViewController"],
        [[TabViewVO alloc]initWithTitle:@"UIView阴影" Target:@"ShadowViewController"],
    ];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView reloadData];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
    }
    cell.textLabel.text = self.dataSource[indexPath.row].title;
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Class cls = NSClassFromString(self.dataSource[indexPath.row].target);
    UIViewController *vc = [[cls alloc] init];
    vc.view.backgroundColor = [UIColor whiteColor];
    vc.title = self.dataSource[indexPath.row].title;
    [self.navigationController pushViewController:vc animated:YES];
}
@end
